package com.yzf.demo.demo.io;

import java.io.FileReader;
import java.io.FileWriter;

/**
 * Created by 于占峰 on 2020/4/5/005.
 * 字符流
 */
public class ReaderWriterDemo {

    public static void main(String[] args) {
        try {
            FileReader fileReader = new FileReader("G:/终结处理和垃圾回收抄录.MD");
            FileWriter fileWriter = new FileWriter("G:/123.txt");
            int len = 0;
            char[] chars = new char[1024];
            while ((len = fileReader.read(chars)) != -1) {
                fileWriter.write(chars, 0, len);
            }
            fileWriter.flush();//要刷新缓存 不然会无法触发写入操作
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
